package com.powernode.teatraceability.dao.plateprocessmgt;

import com.powernode.teatraceability.pojo.plateprocessmgt.ProductionEnvironment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProductionEnvironmentMapper {

    @Select("select * from t_schj where qydm = #{qydm} order by bh desc")
    List<ProductionEnvironment> selectAll(String qydm);

    @Select("select * from t_schj where qydm = #{qydm} and t_schj.chandi like concat('%',#{chandi},'%')")
    List<ProductionEnvironment> selectLikeByChandi(@Param("chandi") String chandi, @Param("qydm") String qydm);

    @Select("select distinct(chandi) from t_schj where qydm = #{qydm}")
    List<String> selectCdName(String qydm);

    @Select("select avg(ph) ph,avg(trwd) trwd, avg(trsd) trsd from t_schj group by chandi")
    ProductionEnvironment selectOne(String chandi);
    @Select("select chandi from t_schj where bh = #{bh}")
    String getChandi(String bh);
    @Update("update t_schj " +
            "set chandi=COALESCE(#{chandi}, chandi), ph=COALESCE(#{ph}, ph), trwd=COALESCE(#{trwd}, trwd), " +
            "trsd=COALESCE(#{trsd}, trsd), gxrq=COALESCE(#{gxrq}, gxrq) " +
            "where bh = #{bh}")
    int update(ProductionEnvironment productionEnvironment);

    @Insert("insert into t_schj(qydm, chandi, ph, trwd, trsd, gxrq) values(#{qydm}, #{chandi}, #{ph}, #{trwd}, #{trsd}, #{gxrq})")
    int insert(ProductionEnvironment productionEnvironment);
    @Delete("delete from t_schj where bh = #{bh}")
    int delete(String  bh);

}
